package com.example.mytestdemo.customviewbook.eight.com.example.harvic.blogrecyclerviewsec

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.example.mytestdemo.R

class StaggeredActivity : AppCompatActivity() {
    private val mDatas = ArrayList<String>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_staggered)
        generateDatas()
        val mRecyclerView: RecyclerView =
            findViewById<View>(R.id.stagger_recycler_view) as RecyclerView
        //瀑布流布局
        val staggeredManager = StaggeredGridLayoutManager(5, StaggeredGridLayoutManager.VERTICAL)
        mRecyclerView.setLayoutManager(staggeredManager)
        val adapter = StaggeredRecyclerAdapter(this, mDatas)
        mRecyclerView.setAdapter(adapter)
    }

    private fun generateDatas() {
        for (i in 0..199) {
            mDatas.add("第 $i 个item")
        }
    }
}